package com.zone.gateway.core.mapping;

/**
 * @author: zongzi
 * @description: http描述性信息
 * @date: 2025/4/18
 */
public class HttpStatement {

    /** 请求uri */
    private final String uri;
    /** http请求类型 */
    private final HttpCommonType type;
    /** rpc应用上下文 */
    private final String applicationName;
    /** rpc接口全限定名 */
    private final String interfaceName;
    /** rpc方法名 */
    private final String methodName;
    /** 参数类型 */
    private final String paramsType;
    /** 请求是否需要校验 */
    private boolean auth = false;

    private HttpStatement(Build build) {
        this.uri = build.getUri();
        this.type = build.getType();
        this.applicationName = build.getApplicationName();
        this.interfaceName = build.getInterfaceName();
        this.methodName = build.getMethodName();
        this.paramsType = build.getParamsType();
        this.auth = build.isAuth();
    }

    public String getUri() {
        return uri;
    }

    public HttpCommonType getType() {
        return type;
    }

    public String getApplicationName() {
        return applicationName;
    }

    public String getInterfaceName() {
        return interfaceName;
    }

    public String getMethodName() {
        return methodName;
    }

    public String getParamsType() {
        return paramsType;
    }

    public boolean isAuth() {
        return auth;
    }


    @Override
    public String toString() {
        return "HttpStatement{" +
                "uri='" + uri + '\'' +
                ", type=" + type +
                ", applicationName='" + applicationName + '\'' +
                ", interfaceName='" + interfaceName + '\'' +
                ", methodName='" + methodName + '\'' +
                ", paramsType='" + paramsType + '\'' +
                ", auth=" + auth +
                '}';
    }

    /**
     * http statement 构造者
     */
    public static class Build {
        /** 请求uri */
        private String uri;
        /** http请求类型 */
        private HttpCommonType type;
        /** rpc应用上下文 */
        private String applicationName;
        /** rpc接口全限定名 */
        private String interfaceName;
        /** rpc方法名 */
        private String methodName;
        /** 参数类型 */
        private String paramsType;
        /** 请求是否需要校验 */
        private boolean auth = false;

        public Build uri(String uri) {
            this.uri = uri;
            return this;
        }

        public Build type(HttpCommonType type) {
            this.type = type;
            return this;
        }

        public Build applicationName(String applicationName) {
            this.applicationName = applicationName;
            return this;
        }

        public Build interfaceName(String interfaceName) {
            this.interfaceName = interfaceName;
            return this;
        }

        public Build methodName(String methodName) {
            this.methodName = methodName;
            return this;
        }

        public Build paramsType(String paramsType) {
            this.paramsType = paramsType;
            return this;
        }

        public Build auth(boolean auth) {
            this.auth = auth;
            return this;
        }

        public String getUri() {
            return uri;
        }

        public HttpCommonType getType() {
            return type;
        }

        public String getApplicationName() {
            return applicationName;
        }

        public String getInterfaceName() {
            return interfaceName;
        }

        public String getMethodName() {
            return methodName;
        }

        public String getParamsType() {
            return paramsType;
        }

        public boolean isAuth() {
            return auth;
        }

        public HttpStatement build() {
            return new HttpStatement(this);
        }

    }
}
